package org.csu.group4.jpetstore.persistence;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.csu.group4.jpetstore.mybatis.entity.Account;
import org.springframework.stereotype.Component;

import java.util.List;

@Mapper
@Component
public interface AccountDAO {
    @Select("select * from account where userid=#{userid}")
    Account findBySignOn(String userid);

    @Select("select * from account")
    List<Account> findAll();

    @Insert("insert account(userid, email, firstname, lastname, status, addr1, addr2, city, state, zip, country, phone) " +
            "values (#{userid}, #{email}, #{firstname}, #{lastname}, #{status}, #{addr1}, #{addr2}, #{city}, #{state}, #{zip}, #{country}, #{phone})")
    void save(Account account);

    @Update("update account SET email=#{email}, firstname=#{firstname}, lastname=#{lastname}, status=#{status}, addr1=#{addr1}, addr2=#{addr2}, city=#{city}, state=#{state}, zip=#{zip}, country=#{country}, phone=#{phone} where userid=#{userid}")
    void updateAccount(Account account);
}
